import { post } from '@/utils/request';

/**
 * 获取用户企业
 * @param data
 * @returns
 */
export const getCompanys = async (data: object) =>
  post('/users/api/web/user/companys', data);

/**
 * 用户切换企业
 * @param data
 * @returns
 */
export const switchCompany = async (data: object) =>
  post('/users/api/web/user/company-set', data, { requestType: 'form' });

/**
 * 七牛 token 获取
 */
export const getQNToken = (
  data: { useCache?: boolean; bucket: string } = {
    useCache: true,
    bucket: NODE_ENV === 'product' ? 'ugc-pro' : 'ugc-dev',
  },
) => {
  return post<{ host: string; token: string }>(
    `/demeter/api/file/upload/token`,
    data,
  );
};

type menusType = {
  code: string;
  name: string;
  serviceId: number | string;
};
/**
 * 获取菜单权限
 */
export const getMenuListRight = () => {
  return post<menusType[]>(
    '/users/api/web/ep/menu/list-user',
    {
      serviceId: 13, // jarvis系统
    },
    {
      requestType: 'form',
    },
  );
};

export interface cityData {
  blackListStreet: null;
  canOrderCountyList: string[];
  canOrderCountys: string;
  cityId: number;
  cityName: string;
  deleted: number;
  id: number;
  provinceId: number;
  provinceName: string;
}
/**
 * 获取当前服务城市
 */
export function getServiceCity() {
  return post<cityData[]>('/demeter/api/web/ep/service/citys');
}

export interface regionData {
  id: number;
  level: number;
  name: string;
  parentId: number;
  shortName: string;
}
/**
 * 获取城市地区
 */
export function getRegions(params: { parentId?: number; id?: number }) {
  return post<regionData[]>('/users/api/comm/regions', params, {
    requestType: 'form',
  });
}

export function findRegions(params: { name: string; endLevel: 2 }) {
  return post<regionData[]>('/demeter/api/web/ep/regions/find', params, {
    requestType: 'form',
  });
}
